package com.example.QQ;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;

import com.example.QQ.Controller;
import com.example.QQ.ServerThread;

public class Server extends  Thread{
    Controller hell;
    ServerSocket server;
    ArrayList<Socket> arrayList = new ArrayList<>();
    public Server(){

    }
    public Server(Controller hell) {
        this.hell=hell;
    }
    public  void run() {
        //创建服务器ServerSocket对象和系统要指定的端口号
        ServerSocket server = null;
        try {
            server = new ServerSocket(7400);
            //使用ServerSocket对象中的方法accept,获取到请求的客户端对象Socket
            while (true) {
                Socket socket = server.accept();
                arrayList.add(socket);
                new ServerThread(socket,hell).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public ArrayList<Socket> getServer() throws IOException {
        return arrayList;
    }


}
